<template>
  <yd-ls-box>
    <yd-ls-layout :title="title" :onfoot=false  :tolfurl="urls" torgtxt="列表" @handle-rgtxt-button="showlist">
      <div class="yd-ls-height"></div>
      <yd-cell-group class="yd-ls-billcheck-cell">
        <div class="yd-ls-billcheck-hospital-name">{{ checkDetail.hospital_name }}</div>
        <yd-cell-item>
          <span slot="left">{{ checkDetail.chk_time }}</span>
        </yd-cell-item>
        <ul class="yd-ls-billcheck-list">
          <li v-for="items in checkDetail.items" :key="items.chk_demo_id">
            <div>{{ items.chk_item }}</div><div><span  v-if="items.chk_item_code">({{ items.chk_item_code }})</span></div>
            <div>{{(isNaN(items.chk_value*1) == false && items.chk_value*1 >= 10) ? (items.chk_value*1).toExponential().toString().replace('+', '') : (items.chk_value)}} <i>{{ items.unti }}</i></div>
          </li>
        </ul>


      </yd-cell-group>

      <yd-ls-title lftit="结论"></yd-ls-title>
      <yd-ls-content>
        <div slot="content">{{ checkDetail.chk_remark }}</div>
      </yd-ls-content>

      <yd-popup v-model="showitem" position="right">
        <yd-ls-popup-header :noarrow=false headname="检查列表"></yd-ls-popup-header>
        <yd-cell-group
          class="yd-ls-billcheck-detail"
          v-for="items in yearList"
          :title="items.year"
          :key="items.year">
          <yd-cell-item type="radio" v-for="list in items.items" :key="list.chk_id">
            <span slot="left">{{ list.month_day }}</span>
            <input slot="right" type="radio" :value="items.year + '年' + list.month_day" v-model="picked" @click="pickYear(list.chk_id)"/>
          </yd-cell-item>
        </yd-cell-group>
      </yd-popup>
      <div class="yd-ls-height"></div>
    </yd-ls-layout>
    <yd-ls-checkpic-button v-if="imgLen" :imglist="checkDetail.files"></yd-ls-checkpic-button>
  </yd-ls-box>
</template>

<style>

  .yd-ls-billcheck-cell .yd-cell-item:not(:last-child):after {
    border-bottom: 2px solid #d9d9d9;
    margin-left: 0;
  }
  .yd-ls-billcheck-list {
    position: relative;
  }
  .yd-ls-billcheck-list div {
    float: left;
  }
  .yd-ls-billcheck-list div {
    padding: .3rem 0;
  }
  .yd-ls-billcheck-list div:nth-child(1) {
    max-width: 2rem;
    text-overflow:ellipsis;
    overflow:hidden;
    white-space:nowrap;
  }
  .yd-ls-billcheck-list div:nth-child(3) {
    float: right;
  }
  .yd-ls-billcheck-list li {
    padding: 0 .3rem;
  }
  .yd-ls-billcheck-list li:after {
    content: "";
    display: block;
    width: 100%;
    border-bottom: 1px solid #d9d9d9;
    -webkit-transform: scaleY(.5);
    transform: scaleY(.5);
    -webkit-transform-origin: 0 0;
    transform-origin: 0 0;
    clear: both;
  }

  .yd-ls-billcheck-detail {
    margin-bottom: 0;
  }
  .yd-ls-billcheck-detail .yd-cell-title {
    padding-top: .1rem
  }
  .yd-ls-billcheck-detail .yd-cell-left span span {
    display: inline-block;
    width: 1.2rem;
  }

  .yd-ls-billcheck-hospital-name {
    font-size: .36rem;
    font-weight: 600;
    padding: .3rem .3rem 0 .3rem;
  }
</style>
<script>
  import ydLsBox from '../../../components/yd-ls-box.vue'
  import ydLsLayout from '../../../components/yd-ls-layout.vue'
  import ydLsTitle from '../../../components/yd-ls-title.vue'
  import ydLsPopupHeader from '../../../components/yd-ls-popup-header.vue'
  import ydLsContent from '../../../components/yd-ls-content.vue'
  import ydLsCheckpicButton from '../../../components/yd-ls-checkpic-button.vue'
  import api from '../../../axios/api'

  export default {
    name: 'billcase',
    props: {},
    data() {
      return {
        urls: '',
        title: '',
        showitem: false,
        picked: '',
        imgLen: 0,
        checkDetail: [],
        yearList: []
      }
    },
    created() {
      //TODO:初始化数据
      let chkid = this.$route.query.chkid
      let typeid = this.$route.query.typeid
      let psize = (this.$route.query.checksize*1) * (this.$route.query.checkindex*1)
      this.urls = `index.html#/bill?type=1?checksize=${psize}`
      this.getCheckYear(typeid, chkid)
      this.title = this.$route.query.title + '检查'
      sessionStorage.isbillpic = 1
    },
    methods: {
      init() {

      },
      getCheckDetail(id) {
        this.axios.get(api.bill_check_detail,{params:{chk_id:id}})
          .then(m=>{
            let bill_check_detail_data = m.data
            this.checkDetail = bill_check_detail_data.data
            this.imgLen = this.checkDetail.files.length
            this.$dialog.loading.close()
          }).catch(err=>{
            this.$dialog.loading.close()
            this.$dialog.alert({mes:  '检查单详情=' + JSON.stringify(err)})
          })
      },
      getCheckYear(tid, cid) {
        
        this.$dialog.loading.open(api.default_loading_txt);
        this.axios.get(api.bill_check_year,{params:{type_id:tid}})
          .then(m=>{
            let bill_check_year_data = m.data
            this.yearList = bill_check_year_data.data
            for(let item of this.yearList[0].items) {
              if(item.chk_id == cid) {
                this.picked = this.yearList[0].year + '年' + item.month_day
              }
            }
            this.getCheckDetail(cid)
          }).catch(err=>{
            this.$dialog.loading.close()
            this.$dialog.alert({mes: '检查单列表=' + JSON.stringify(err)})
          })
      },
      showlist () {
        this.showitem = true
      },
      pickYear(id) {
        this.$dialog.loading.open(api.default_loading_txt);
        this.getCheckDetail(id)
      }
    },
    mounted() {
      this.init()
    },
    components: { ydLsBox, ydLsLayout, ydLsTitle, ydLsPopupHeader, ydLsContent, ydLsCheckpicButton }


  }
</script>
